﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using MySql.Data;
using MySql.Data.MySqlClient;
namespace LibSystem
{
    public partial class Form1 : Form
    {
        private String ss;
        
        private MySqlCommand mycmd;
        private MySqlDataReader myreader;
        private String mystr;
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            ss = "server=localhost;User Id=root;Database=libaccount;Persist Security Info=True";
            TempData.myconn = new MySqlConnection(ss);
            TempData.myconn.Open();
            

        }

        private void button1_Click(object sender, EventArgs e)
        {

            String mystr = "select * from account where user= '" + textBox1.Text + "'";
            mycmd = new MySqlCommand(mystr, TempData.myconn);
            myreader = mycmd.ExecuteReader();
            myreader.Read();
            try
            {
                if (textBox2.Text == myreader[1].ToString())
                {
                    TempData.user=textBox1.Text;
                    TempData.isManager = (bool)myreader[2];
                    Form2 Form2 = new Form2();
                    Form2.Show();
                    this.Hide();

                }
                else
                    MessageBox.Show("密码错误", "error", MessageBoxButtons.OK);

            }
            catch (Exception err)
            {
                MessageBox.Show("用户名错误", "error", MessageBoxButtons.OK);
            }
            myreader.Close();
        }
    }
}
